import { RouteRecordRaw } from 'vue-router'
import { getToken } from '@/utils/token'

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue'),
    children: [
      {
        path: 'home',
        alias: '',
        name: 'Home',
        component: () => import('../views/Home/index.vue')
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('../views/Menu/index.vue')
      },
      {
        path: 'shopbag',
        name: 'Shopbag',
        component: () => import('../views/shopbag/index.vue')
      },
      {
        path: 'my',
        name: 'My',
        component: () => import('../views/My/index.vue'),
        beforeEnter: (_to, _from, next) => {
          const isLogin = !!getToken()
          if (isLogin === true) {
            next()
          } else {
            next({
              path: '/login'
            })
          }
        }
      }
    ]
  },
  {
    path: '/shopMes',
    name: 'ShopMes',
    component: () => import('../views/shopMes/index.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/personal',
    name: 'Personal',
    component: () => import('../views/personal/index.vue')
  },
  {
    path: '/collect',
    name: 'Collect',
    component: () => import('../views/collect/index.vue')
  },
  {
    path: '/myOrder',
    name: 'MyOrder',
    component: () => import('../views/myOrder/index.vue')
  },
  {
    path: '/address',
    name: 'Address',
    component: () => import('../views/address/index.vue')
  },
  {
    path: '/newAddress',
    name: 'NewAddress',
    component: () => import('../views/newAddress/index.vue')
  },
  {
    path: '/editAddress',
    name: 'EditAddress',
    component: () => import('../views/editAddress/index.vue')
  },
  {
    path: '/orderSubmit',
    name: 'OrderSubmit',
    component: () => import('../views/orderSubmit/index.vue')
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('../views/search/index.vue')
  },
  {
    path: '/safe',
    name: 'Safe',
    component: () => import('../views/safe/index.vue')
  },
  {
    path: '/forgetPassword',
    name: 'ForgetPassword',
    component: () => import('../views/forgetPassword/index.vue')
  },
  {
    path: '/passwordReset',
    name: 'PasswordReset',
    component: () => import('../views/passwordReset/index.vue')
  }
]
